#include "Property.h"

using namespace cmn;

namespace editor_core {

	Property::Property( const Property& property ) :
		m_key( property.m_key ),
		m_name( property.m_name ),
		m_value( property.m_value ),
		m_children( property.m_children )
	{}

	Property::Property( int key, const std::string& name, const PropertyValue& value ) :
		m_key( key ),
		m_name( name ),
		m_value( value )
	{}

	void Property::AddChild( const Property& child ) {
		m_children.Add( child );
	}

	void Property::RemoveChild( const Property& child ) {
		m_children.Remove( child );
	}

	void Property::GetChildren( ICollection<Property>& children ) const {
		for( IteratorPtr<Property> propertiesIter( m_children );
				!propertiesIter.IsEnd();
				propertiesIter.Next() )
		{
			children.Add( propertiesIter.Current() );
		}
	}

	bool operator== ( const Property& a, const Property& b ) {
		if(	a.GetKey() != b.GetKey() ) return false;
		if( a.GetValue() != b.GetValue() ) return false;
		if( a.GetName() != b.GetName() ) return false;

		Vector<Property> chldrenA;
		Vector<Property> chldrenB;
		a.GetChildren( chldrenA );
		b.GetChildren( chldrenB );
		return IterablesAreEqual( chldrenA, chldrenB );
	}

	bool operator!= ( const Property& a, const Property& b ) {
		if(	a.GetKey() != b.GetKey() ) return true;
		if( a.GetValue() != b.GetValue() ) return true;
		if( a.GetName() != b.GetName() ) return true;

		Vector<Property> chldrenA;
		Vector<Property> chldrenB;
		a.GetChildren( chldrenA );
		b.GetChildren( chldrenB );
		return !IterablesAreEqual( chldrenA, chldrenB );
	}
}
